package com.example.CarManagement.sys.controller;

import com.example.CarManagement.common.Result;
import com.example.CarManagement.sys.entity.Notification;
import com.example.CarManagement.sys.service.impl.NotificationServiceImpl;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;

/**
 * <p>
 * 通知表 前端控制器
 * </p>
 *
 * @author 徐佳彪
 * @since 2025-07-08
 */
@RestController
@RequestMapping("/sys/notification")
public class NotificationController {

    @Resource
    private NotificationServiceImpl notificationService;


    // 添加通知
    @PreAuthorize("@se.hasPermi('NOTIFICATION_INSERT')")
    @PostMapping("/add")
    public Result<?> add(@RequestBody Notification notification, @RequestHeader("Authorization") String token) {
        return notificationService.add(notification, token);
    }

    @PreAuthorize("@se.hasPermi('NOTIFICATION_SELECT')")
    @GetMapping("/page")
    public Result<?> page(@RequestParam Integer pageNo, @RequestParam Integer pageSize, @RequestHeader("Authorization") String token) {
        return Result.success(notificationService.selectPage(pageNo, pageSize, token));
    }

    // 查询当前自己的所有通知
    @PreAuthorize("@se.hasPermi('NOTIFICATION_SELECT')")
    @GetMapping("/selfNotice")
    private Result<?> selfNotice(@RequestHeader("Authorization") String token) {
        return notificationService.selfNotice(token);
    }

    // 删除通知
    @PreAuthorize("@se.hasPermi('NOTIFICATION_DELETE')")
    @DeleteMapping("/delete/{id}")
    public Result<?> delete(@PathVariable("id") String id) {
        return Result.success(notificationService.removeById(id));
    }

    // 修改通知
    @PreAuthorize("@se.hasPermi('NOTIFICATION_UPDATE')")
    @PutMapping("/update")
    public Result<?> update(@RequestBody Notification notification) {
        return Result.success(notificationService.updateById(notification));
    }

}
